<!-- 查询-已关闭门店-->
<template>
  <div class="queryClosed">
    <CommonBtn label-name="关闭门店信息查询" v-if="!button || (button.event!='add()' && button.event!='edit()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked && item.label && item.valueName != undefined">{{item.label+":"+item.valueName}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!showEdit" :buttons="buttons" :columns="columns" :listUrl="listUrl" :conditions="conditions" @tableSelect="tableSelect" @dbClick="openItem"></CommonList>
    <StoreEdit :pageType="pageType"
                  ref="storeEdit"
                  :disabled="!enableEdit"
                  :label="editTitle"
                  v-if="showEdit"
                  :items="items"
                  :originalData="row"
                  @editBack="editBack"
                  @search="search"
                  @submit="submit" />
    <CommonSearch :label="item.label"
                  :conditions="item.conditions"
                  v-for="(item, index) of searchs"
                  :key="index"
                  :listUrl="item.listUrl"
                  :columns="item.columns"
                  :items="item.items"
                  :page="item.page"
                  :pageType= "pageType"
                  :originalData="item.searchData"
                  @search="search"
                  @submit="item.selectItem"
                  @searchBack="searchBack"/>
    <CommonExport :out-btn="button" :props="columns" :export_type="export_type"
                  @close="close" :export-url="$api.API_MDMRETAIL_INFO_EXPORT" :conditions="conditions"></CommonExport>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList"
    import CommonBtn from "../../common/CommonBtn";
    import CommonSearch from '../../common/CommonSearch'
    import StoreEdit from "./StoreEdit";
    import CommonExport from "../../common/CommonExport";
    export default {
        name:'queryClosed',
        data(){
            return{
              searchData: {},
              searchItems: [],
              searchs:[],
              pageType: -1,
              showEdit: false,
              enableEdit: false,
              editTitle: '',
              conditions:[{prop: "flag", value: 3, checked: true}],
                buttons:[
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'mdmCode',
                        label:'统一编码'
                    },
                    {
                        prop:'retailName',
                        label:'门店名称'
                    },
                    {
                        prop:'cooperationStatus',
                        label:'合作状态'
                    },
                    {
                        prop:'dataSource',
                        label:'数据来源'
                    },
                    {
                        prop:'retailGroup',
                        label:'所属集团客户'
                    },
                    {
                        prop:'isLKAvalue',
                        label:'是否LKA'
                    },
                    {
                        prop:'retailType',
                        label:'门店类型'
                    },
                    {
                        prop:'locationName',
                        label:'Location'
                    },
                    {
                        prop:'province',
                        label:'省'
                    },
                    {
                        prop:'cityName',
                        label:'市'
                    },
                    {
                        prop:'adminCity',
                        label:'区县'
                    },
                    {
                        prop:'deAddress',
                        label:'详细地址'
                    },
                    {
                        prop:'repName',
                        label:'负责人'
                    },
                    {
                        prop:'remark',
                        label:'Remark'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    },
                ],
                listUrl:this.$api.API_GET_DOWNRETAIL_LIST,
                button:null,
                row: null,
                export_type:[{
                    checked: true,
                    prop: 'flag',
                    value: '3'
                }],
                items: [
                {
                    name: '统一编码',
                    key: 'mdmCode',
                    type: 'text',
                    disable: true,
                    required: false,
                    placeholder: '待生成'
                },
                {
                  name: '门店名称',
                  key: 'retailName',
                  type: 'text',
                  disable: false,
                  required: true,
                  placeholder: ''
                },
                {
                  name: '地理城市',
                  key: 'city',
                  type: 'multi-select',
                  required: false,
                  optionss: [{
                    options: [],
                    key: 'province'
                  }, {
                    options: [],
                    key: 'physicalCity'
                  }, {
                    options: [],
                    key: 'adminCity'
                  }]
                },
                {
                  name: '城市类别',
                  key: 'cityTypeName',
                  vkey: 'fkCityType',
                  type: 'single-select',
                  required: false,
                  disable: true,
                  options: []
                },
                {
                  name: '详细地址',
                  key: 'deAddress',
                  type: 'multi-text',
                  required: false,
                  texts: [{
                    key: 'address',
                    name: '街道',
                    span: 12
                  }, {
                    key: 'address1',
                    name: '路',
                    span: 12
                  }, {
                    key: 'address2',
                    name: null,
                    span: 24
                  }]
                },
                {
                  name: '经纬度',
                  type: 'location',
                  key1: 'longitude',
                  key2: 'latitude',
                  disable: true,
                },
                {
                  name: '门店类型',
                  key: 'retailType',
                  vkey: 'fkRetailType',
                  type: 'single-select',
                  required: false,
                  disable: false,
                  options: []
                },
                {
                  name: 'Location',
                  key: 'locationName',
                  vkey: 'fkLocation',
                  type: 'single-select',
                  required: false,
                  disable: true,
                  placeholder: '请选择'
                },
                {
                  name: '门店投资属性',
                  key: 'levelName',
                  vkey: 'fkLevel',
                  type: 'single-select',
                  required: false,
                  disable: true,
                  options: []
                },
                {
                  name: '所属客户集团',
                  key: 'retailGroup',
                  type: 'search',
                  required: false,
                  disable: false
                },
                {
                  name: '是否LKA',
                  key: 'isLKAvalue',
                  type: 'search',
                  required: false,
                  disable: false
                },
                {
                  name: '强生负责人',
                  key: 'repName',
                  type: 'search',
                  required: true,
                  disable: false
                },
                {
                  name: '门店联系人姓名',
                  key: 'linkMan',
                  type: 'text',
                  required: false,
                  disable: false
                },
                {
                  name: '门店联系人电话',
                  key: 'tel',
                  type: 'text',
                  required: false,
                  disable: false
                },
                {
                  name: '门店联系人邮箱',
                  key: 'retailerMail',
                  type: 'text',
                  required: false,
                  disable: false,
                  placeholder: '多个邮箱请用英文,(逗号分割)'
                },
                {
                  name: '门店营业年月',
                  key: 'businessTime',
                  type: 'date',
                  year: 'businessYear',
                  month: 'businessMonth',
                  options: [],
                  required: true,
                  disable: false,
                  placeholder: '请选择'
                },
                {
                  name: '营业状态',
                  key: 'businessStatus',
                  vkey: 'businessStatus',
                  type: 'single-select',
                  required: false,
                  disable: false,
                  placeholder: '请选择'
                },
                {
                  name: '合作状态',
                  key: 'cooperationStatus',
                  vkey: 'cooperationStatus',
                  type: 'single-select',
                  required: false,
                  disable: true,
                  placeholder: '请选择'
                },
                {
                  name: 'Destination',
                  key: 'destinationName',
                  vkey: 'fkDestination',
                  type: 'single-select',
                  required: false,
                  disable: true,
                  placeholder: '请选择'
                },
                {
                  name: 'Remark',
                  key: 'remark',
                  type: 'text',
                  required: false,
                  disable: false
                },
                {
                  name: '是否Promoter覆盖',
                  key: 'isPromoter',
                  type: 'checkbox',
                },
                {
                  name: '是否B2B生意覆盖',
                  key: 'isB2b',
                  type: 'checkbox',
                },
                {
                  name: '是否销售强生商品',
                  key: 'isSalesjnj',
                  type: 'checkbox',
                }]
            }
        },
        methods:{
          onButtonClick(item) {
              this.enableEdit = true
              if (item.event == 'edit()') {
                if (!this.row || JSON.stringify(this.row) == '{}') {
                  this.$message.error("请选择一行数据")
                  return
                }
                this.editTitle = '编辑门店信息'
                this.showEdit = true
              }

              if (item.event == 'add()') {
                  this.showEdit = true
                  this.editTitle = '新增门店信息'
                  this.row = null
              }
              let self = this
              if (item.event == 'search()') {
                this.searchs.push({
                  label: '查询门店信息',
                  page: 'store',
                  searchData: this.searchData,
                  items: this.searchItems,
                  selectItem: function (formData, items) {
                    self.searchs.pop()
                    self.searchItems = items;
                    self.searchData = formData;
                    let conditions = self.conditions.filter(item=>{
                      return !item.label
                    })
                    // 回调
                    for (let idx in items) {
                      let item = items[idx]
                      if (item.checked == true) {
                        conditions.push({
                          checked: true,
                          label: item.name,
                          prop: item.vkey ? item.vkey : item.key,
                          valueName: formData[item.key],
                          value: item.vkey ? formData[item.vkey] : formData[item.key]
                        })
                      }
                    }
                    self.conditions = conditions
                  },
                })
              }
              this.button = item
          },
          search(item, callback) {
            let self = this
            if (item.key == 'repName') {
              // 客户属性
              this.searchs.push({
                label: '人员信息',
                conditions: [],
                listUrl: this.$api.API_GETTPINFO_LIST,
                selectItem: function (item) {
                  self.searchs.pop()
                  // 回调
                  if (typeof(callback) == 'function') {
                    callback({repName: item.repName, fkRep: item.pkid})
                  }
                },
                items: [{
                  name: '员工姓名',
                  key: 'repName',
                  type: 'text',
                },{
                  name: '员工账号',
                  key: 'repCode',
                  type: 'text',
                },{
                  name: '所属管理层级',
                  key: 'positionName',
                  type: 'search',
                },{
                  name: 'WWID',
                  key: 'wWID',
                  type: 'text',
                },{
                  name: 'SAP代码',
                  key: 'sapCode',
                  type: 'text',
                },{
                  name: '总部/大区',
                  key: 'hQOrRegion',
                  type: 'text',
                }],
                columns: [{
                  prop: 'repName',
                  label: '员工姓名'
                },{
                  prop: 'repCode',
                  label: '员工账号'
                },{
                  prop: 'positionName',
                  label: '所属管理层级'
                },{
                  prop: 'WWID',
                  label: 'wWID'
                },{
                  prop: 'sapCode',
                  label: 'SAP代码'
                },{
                  prop: 'hQOrRegion',
                  label: '总部/大区'
                }]
              })
            }
          },
          editBack() {
              this.showEdit = false
              this.button = null
          },
          tableSelect(item) {
            this.row = item
            this.button = null
          },
          openItem(item) {
            // 打开详情
            this.showEdit = true
            this.enableEdit = false
            this.editTitle = '查看门店信息'
          },
          searchBack() {
            this.searchs.pop()
          },
          submit(formData) {
          },
            close(item) {
                this.button = item
            }
        },
        components:{CommonExport,CommonList,CommonBtn,StoreEdit, CommonSearch}
    }
</script>
